﻿using System;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using Microsoft.CSharp.RuntimeBinder;

namespace YArchitech.Temp
{
	public static class Utility
	{
		public static int GenerateId()
		{
			return BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0);
		}

		public static string GenerateGuid()
		{
			return Guid.NewGuid().ToString();
		}

		public static bool IsZero(double d, double prec = 1E-05)
		{
			return Math.Abs(d) < prec;
		}

		public static bool IsEqual(double a, double b, double prec = 1E-05)
		{
			return Utility.IsZero(a - b, prec);
		}

		public static double Volume(double mass, double density)
		{
			if (Utility.IsZero(density, 1E-05))
			{
				return 0.0;
			}
			return mass / density;
		}

		public static double Mass(double volume, double density)
		{
			return volume * density;
		}

        public static bool InZone(dynamic dTest, dynamic d1, dynamic d2)
        {
            return false;
        }
        //{
        //    if (Utility.<>o__15.<>p__2 == null)
        //    {
        //        Utility.<>o__15.<>p__2 = CallSite<Func<CallSite, object, bool>>.Create(Binder.UnaryOperation(CSharpBinderFlags.None, ExpressionType.IsTrue, typeof(Utility), new CSharpArgumentInfo[]
        //        {
        //            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
        //        }));
        //    }
        //    Func<CallSite, object, bool> target = Utility.<>o__15.<>p__2.Target;
        //    CallSite <>p__ = Utility.<>o__15.<>p__2;
        //    if (Utility.<>o__15.<>p__1 == null)
        //    {
        //        Utility.<>o__15.<>p__1 = CallSite<Func<CallSite, object, int, object>>.Create(Binder.BinaryOperation(CSharpBinderFlags.None, ExpressionType.GreaterThan, typeof(Utility), new CSharpArgumentInfo[]
        //        {
        //            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
        //            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null)
        //        }));
        //    }
        //    Func<CallSite, object, int, object> target2 = Utility.<>o__15.<>p__1.Target;
        //    CallSite <>p__2 = Utility.<>o__15.<>p__1;
        //    if (Utility.<>o__15.<>p__0 == null)
        //    {
        //        Utility.<>o__15.<>p__0 = CallSite<Func<CallSite, object, object, object>>.Create(Binder.InvokeMember(CSharpBinderFlags.None, "CompareTo", null, typeof(Utility), new CSharpArgumentInfo[]
        //        {
        //            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
        //            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
        //        }));
        //    }
        //    object arg;
        //    object arg2;
        //    if (target(<>p__, target2(<>p__2, Utility.<>o__15.<>p__0.Target(Utility.<>o__15.<>p__0, d1, d2), 0)))
        //    {
        //        arg = d1;
        //        arg2 = d2;
        //    }
        //    else
        //    {
        //        arg2 = d1;
        //        arg = d2;
        //    }
        //    if (Utility.<>o__15.<>p__7 == null)
        //    {
        //        Utility.<>o__15.<>p__7 = CallSite<Func<CallSite, object, bool>>.Create(Binder.Convert(CSharpBinderFlags.None, typeof(bool), typeof(Utility)));
        //    }
        //    Func<CallSite, object, bool> target3 = Utility.<>o__15.<>p__7.Target;
        //    CallSite <>p__3 = Utility.<>o__15.<>p__7;
        //    if (Utility.<>o__15.<>p__3 == null)
        //    {
        //        Utility.<>o__15.<>p__3 = CallSite<Func<CallSite, object, object, object>>.Create(Binder.BinaryOperation(CSharpBinderFlags.None, ExpressionType.GreaterThanOrEqual, typeof(Utility), new CSharpArgumentInfo[]
        //        {
        //            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
        //            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
        //        }));
        //    }
        //    object obj = Utility.<>o__15.<>p__3.Target(Utility.<>o__15.<>p__3, dTest, arg2);
        //    if (Utility.<>o__15.<>p__6 == null)
        //    {
        //        Utility.<>o__15.<>p__6 = CallSite<Func<CallSite, object, bool>>.Create(Binder.UnaryOperation(CSharpBinderFlags.None, ExpressionType.IsFalse, typeof(Utility), new CSharpArgumentInfo[]
        //        {
        //            CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
        //        }));
        //    }
        //    object arg4;
        //    if (!Utility.<>o__15.<>p__6.Target(Utility.<>o__15.<>p__6, obj))
        //    {
        //        if (Utility.<>o__15.<>p__5 == null)
        //        {
        //            Utility.<>o__15.<>p__5 = CallSite<Func<CallSite, object, object, object>>.Create(Binder.BinaryOperation(CSharpBinderFlags.BinaryOperationLogical, ExpressionType.And, typeof(Utility), new CSharpArgumentInfo[]
        //            {
        //                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
        //                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
        //            }));
        //        }
        //        Func<CallSite, object, object, object> target4 = Utility.<>o__15.<>p__5.Target;
        //        CallSite <>p__4 = Utility.<>o__15.<>p__5;
        //        object arg3 = obj;
        //        if (Utility.<>o__15.<>p__4 == null)
        //        {
        //            Utility.<>o__15.<>p__4 = CallSite<Func<CallSite, object, object, object>>.Create(Binder.BinaryOperation(CSharpBinderFlags.None, ExpressionType.LessThanOrEqual, typeof(Utility), new CSharpArgumentInfo[]
        //            {
        //                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
        //                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
        //            }));
        //        }
        //        arg4 = target4(<>p__4, arg3, Utility.<>o__15.<>p__4.Target(Utility.<>o__15.<>p__4, dTest, arg));
        //    }
        //    else
        //    {
        //        arg4 = obj;
        //    }
        //    return target3(<>p__3, arg4);
        //}

		public const double PRECISION1 = 0.1;

		public const double PRECISION2 = 0.01;

		public const double PRECISION3 = 0.001;

		public const double PRECISION4 = 0.0001;

		public const double PRECISION5 = 1E-05;

		public const double PRECISION6 = 1E-06;

		public const double PRECISION7 = 1E-07;

		public const double PRECISION8 = 1E-08;

		public const double PRECISION9 = 1E-09;
	}
}
